require(['./config'], () => {
    require(['header','footer'], () => {
        class Registe {
            constructor() {
              this.addData()
            } 
      // addData ()
      addData () {       
        $('#btn').on('click',  function() {
          let phone = $('#txtCellPhone').val()
          let username = $('#pwd').val()
          let password = $('#password').val()
      
          let data = localStorage.getItem('data')
          console.log(username)
          if(phone && username && password){
            if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phone))){ 
              alert("手机号码有误，请重填");  
              return false; 
          } else{
              if(data){
                data = JSON.parse(data)
                let isData = data.some( name => {
                    return name.username == $('#pwd').val() 
                })
                if (isData == true) {
                    alert('你输入的用户名重复了')
                } else {                                          
                    data.push({ username, password })
                    localStorage.setItem('data', JSON.stringify(data))
                    alert('登录成功即将返回登录页面')
                    window.location.href = '/html/denglu.html'
                }
              }else{
                let  arr = [{username,password}]
                   localStorage.setItem('data',JSON.stringify(arr))
                   alert('登录成功即将返回登录页面')
                   window.location.href = '/html/denglu.html'
              }
          }
          }else{
            alert('请输入数值不能为空')
          }
        })
       
      }
    }
    new Registe
    })
     
})